/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Akanksha;
import javax.swing.JOptionPane;
import java.awt.Toolkit;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import sun.audio.AudioPlayer;
import sun.audio.AudioStream;


/**
 * ALARM,SMOKE DETECTOR Sound from Sounddogs.com
 * http://www.sounddogs.com/results.asp?Type=1,&CategoryID=1029&SubcategoryID=2
 * 
 * Convert MP3 to AU for AudioStream
 * http://www.convertfiles.com/convert/audio/MP3-to-AU.html
 * 
 * @author Akanksha Chauhan
 */
public class Alarm {
    private String alarmMessage;
    private String alarmFile = "Alarm.au";
    
    public int confirm(String message){
        this.alarmMessage = message;
        //Pops up the confirmation window
        int result = JOptionPane.showConfirmDialog(null, alarmMessage);
        return result;
    }
    
    public void setAlarm(String message){
        this.alarmMessage = message;
        // Pops up the warning message box
        JOptionPane.showMessageDialog(null,alarmMessage, "WARNING !!!!!!" , JOptionPane.WARNING_MESSAGE);
        // Makes a beep sound when warning appears
        Toolkit.getDefaultToolkit().beep();  
        
    }
    
    ///Plays the sound contained in the alarmFile attribute of the Alarm Class
    public void play(){
        try {
            InputStream in = new FileInputStream(alarmFile);
            AudioStream audioStream = new AudioStream(in);
            AudioPlayer.player.start(audioStream);
        } catch (FileNotFoundException ex) {
            SipLogger.Instance().error(ex.getMessage());
        } catch (IOException ex) {
            SipLogger.Instance().error(ex.getMessage());
        }
    }
    
    ///Used for testing this class
//    public static void main (String args[]){
//        Alarm alarm = new Alarm();
//        alarm.play();
//    }    
}
